﻿package com
{
	import flash.display.MovieClip;
	import flash.display.Loader;
	import flash.events.ProgressEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.display.*;
	import flash.events.*;
	
	import fl.transitions.*;
	import fl.transitions.easing.*;
	import flash.utils.Timer;
	//import mx.transitions.*;
	//import mx.transitions.easing.*;

	
	public dynamic class Thumb extends MovieClip
	{
		public var _id:String;
		private var timer:Timer;
		
		public function Thumb(imgObj:Object) 
		{
			loadThumb(imgObj);
			_id = imgObj.id;
			timer = new Timer(30,0);
		}
	
		public function update(e:ProgressEvent):void 
		{
			var percent:Number = Math.floor( (e.bytesLoaded*100)/e.bytesTotal );
			if (preloader is MovieClip) 
			{
				preloader.gotoAndStop(percent);
				load_txt.text = percent+"%";
			}
			if (percent == 100) 
			{
				dispatchEvent(new Event("ThumbLoaded", true));
				this.addEventListener(MouseEvent.CLICK,thumbClicked);
				this.addEventListener(MouseEvent.MOUSE_OVER,thumbOver);
				this.addEventListener(MouseEvent.MOUSE_OUT,thumbOut);
				preloader.alpha = 0;
				removeChild(load_txt);
				removeChild(loaderTxt);
			}
		}
		
		private function loadThumb(imgObj:Object):void
		{
			var loader:Loader = new Loader();
			loader.load(new URLRequest(imgObj.thumb));
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, update);
			addChild(loader);
		}
		
		private function thumbClicked(evt:Event):void
		{
			dispatchEvent(new DataEvent("ThumbClicked", true,false,_id));
		}
		private function thumbOver(evt:Event):void
		{
			fade(false);
		}
		private function thumbOut(evt:Event):void
		{
			fade(true);
		}
		
		
		public function fade(IN:Boolean):void
		{
			//TransitionManager.start(this as MovieClip, {type:Fade, direction:Transition.OUT, duration:9, easing:Strong.easeOut});
			
			if(IN)
			{
				this.alpha = 1;
				
			}
			else
			{
				this.alpha = 0.5;
			}
		}		
	}
}
	

